package Work0609;

import java.io.*;
import java.net.*;
import java.util.Scanner;

/**
 * 1:服务器上存有多个用户对象（包括用户和密码），客户端通过socket登录，如果成功，输出欢迎信息，失败给出提示。
 * 
 * @author Y
 *
 */
public class Client {

	public static void main(String[] args) throws IOException {
		Scanner input = new Scanner(System.in);
		Socket s = new Socket("localhost", 9989);
		try {
			boolean p = true;
			InputStream in = s.getInputStream();
			OutputStream out = s.getOutputStream();
			BufferedReader i = new BufferedReader(new InputStreamReader(in));
			PrintWriter o = new PrintWriter(out);
			while (p) {
				System.out.println("输入用户名和密码:");
				o.println(input.next());
				o.flush();
				o.println(input.next());
				o.flush();
				// o.println(input.next());
				String str = i.readLine();
				System.out.println("来自服务器的话" + str);
				if (str.equals("登录成功")) {
					p = false;
				}
			}
		} catch (UnknownHostException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} catch (IOException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} finally {
			try {
				s.close();
			} catch (IOException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
		}

	}

}
